package com.wlz.consumer.consumer;

import com.wlz.api.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.CompletableFuture;

/**
 *   异步调用
 * @author wlz
 * @date 2022-07-12  11:58 下午
 */
@Slf4j
@EnableAutoConfiguration
public class AsyncDubboConsumerDemo {


    @Reference(version = "async")
    private DemoService demoService;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(AsyncDubboConsumerDemo.class, args);

        DemoService demoService = context.getBean(DemoService.class);

        CompletableFuture<String> future = demoService.sayHelloAsync("wlz async .....");

        future.whenComplete((v, t) -> {
            if (t != null) {
                t.printStackTrace();
            }else {
                log.info("result:  {}", v);
            }
        });

        log.info("AsyncDubboConsumerDemo end ....");
    }
}
